from bs4 import BeautifulSoup
from loguru import logger


class WjwParser:
    def __init__(self):
        pass

    def parse_risk_url(self, html):
        soup = BeautifulSoup(html, "lxml")
        a_tags = soup.find_all("a")
        all_risk_urls = []
        for a_tag in a_tags:
            if "title" in a_tag.attrs and "本市各区确诊病例" in a_tag['title']:
                logger.info(f"解析到url: [{a_tag['title']}]{a_tag['href']}")
                all_risk_urls.append(a_tag['href'])
        return all_risk_urls

    def parse_area_url(self, html):
        soup = BeautifulSoup(html, "lxml")
        a_tags = soup.find_all("a")
        area_urls = []
        for a_tag in a_tags:
            if "title" in a_tag.attrs and "划分情况" in a_tag['title']:
                logger.info(f"解析到url: [{a_tag['title']}]{a_tag['href']}")
                area_urls.append(a_tag['href'])
        return area_urls
